<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
use Illuminate\Database\Query\Builder;

class UserController extends Controller
{
    public function upload(Request $request){
        $file = $request->file('avatar');
        $fileName = time().str_random(6).'.'.$file->getClientOriginalExtension();
        $savePath = storage_path('/');
        if(!file_exists($savePath)){
            mkdir($savePath,0755,true);
        }
        $file->move($savePath, $fileName);
        $path = storage_path('/'.$fileName);
//        $f = file_get_contents($path);
        dd($path);
//        return response()->download($path);
    }
    
    function toupload(){
        return view('upload');
    }
    
    function showImage(){
        return response()->file(Storage::url('mt1QpF1KXoz84AO8wg2tqtLdyrNUA6vxUxZVsCFq.jpeg'));
    }
}
